package serialization;
/*
序列化流的作用是：可以在流中，以字节的形式直接读写对象
 */
import java.io.*;

public class Demo1 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        //对象使用序列化流 需要 类实现Serializable接口
        readObject();
        //writeObject();

    }

    private static void  readObject() throws IOException, ClassNotFoundException {
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("HDay09\\A.txt"));
        Object o = ois.readObject();
        ois.close();
        System.out.println(o);
    }

    private static void writeObject() throws IOException {
        Student stu = new Student("张三",19);
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("HDay09\\A.txt"));
        oos.writeObject(stu);
        oos.close();
    }
}
